﻿using System.ComponentModel.DataAnnotations;
using TiaoTaoHelper.Extension.String;

namespace HengTong.Model.Attributes;

public class IdCardValidationAttribute : ValidationAttribute
{
    public IdCardValidationAttribute()
    {
        ErrorMessage = "身份证号码格式不正确";
    }

    public override bool IsValid(object value)
    {
        if (value == null || string.IsNullOrEmpty(value.ToString()))
            return true; // 空值由Required特性处理

        return value.ToString().CheckIdCardNo();
    }
}